package cn.itrip.auth.service.sms;

import com.cloopen.rest.sdk.CCPRestSmsSDK;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
public class SmsServiceImpl implements SmsService {

    @Override
    public void send(String to, String templateId, String[] datas) throws Exception {
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init("app.cloopen.com","8883");
        sdk.setAccount("8aaf07087d7fb5f6017d8f6bef2f02e1","1c44c6442e674f59b52f4ddbdc238302");
        sdk.setAppId("8aaf07087d7fb5f6017d8f6bf07502e8");
        HashMap result =  sdk.sendTemplateSMS(to,templateId,datas);
        if("000000".equals(result.get("statusCode"))){
            System.out.println("短信发送成功");
        }else{
            throw  new Exception(result.get("statusCode").toString()+":"+result.get("statusMsg").toString());
        }
    }
}
